//
//  TabBarViewController.m
//  Distributor
//
//  Created by 主事丫环 on 2019/5/5.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomeViewController.h"
#import "TransactionController.h"
#import "NewsViewController.h"
#import "MineViewController.h"
@interface TabBarViewController ()

@end

@implementation TabBarViewController
-(void)viewWillAppear:(BOOL)animated
{
    // 适配iOS13导致的bug
    if (@available(iOS 13.0, *)) {
        self.tabBar.tintColor = [UIColor colorWithHexString:@"#FF7422"];
    }

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self BjidailisBMoney];
}

-(void)BjidailisBMoney{
    HomeViewController *vc1 = [[HomeViewController alloc] init];
    [self addOneChildVc:vc1 title:@"首页" imageName:@"首页未选中" selectedImageName:@"首页已选中"];

    TransactionController *vc2 = [[TransactionController alloc] init];
    [self addOneChildVc:vc2 title:@"交易" imageName:@"交易未选中" selectedImageName:@"交易已选中"];

    NewsViewController *vc3 = [[NewsViewController alloc] init];
    [self addOneChildVc:vc3 title:@"资讯" imageName:@"资讯未选中" selectedImageName:@"资讯已选中"];
    
    MineViewController *vc4 = [[MineViewController alloc] init];
    [self addOneChildVc:vc4 title:@"我的" imageName:@"我的未选中" selectedImageName:@"我的已选中"];
}

- (void)addOneChildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
    UIImage *normalImage = [UIImage imageNamed:imageName];
    UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:normalImage selectedImage:selectedImage];
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FF7422"]} forState:UIControlStateSelected];
     [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -3.5)];

    BaseNavViewController *nav = [[BaseNavViewController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
 
}
@end
